$().ready(function(){
    var param = getSearch();
    var nav = param[0].split('=')[1];
    var item = param[1].split('=')[1];
    var navList = setNavList(Number(nav));
    var breadcream = '<a href="index.html">首页</a>';
    breadcream += '<a href="'+navList.link+'">'+navList.title+'</a>';
    breadcream += '<a href="">'+navList.list[item].navTitle+'</a>';
    $('#breadcream').html(breadcream);
    var apiUrl;
    if(item == 0){
        apiUrl = global.url + 'Api/New/get_jtxw'
    }
    if(item == 1){
        apiUrl = global.url + 'Api/New/get_hydt'
    }
    var page = 1;
    var newsList;
    function getNewsList(apiUrl,page){
        sendAjax(apiUrl,res=>{
            console.log(res);
            var html = '';
            if(res.list.length == 0){
                html = '<div class="m-no-news">-暂无新闻-</div>'
            }else{
                if(page == 1){
                    newsList = [];
                    newsList = res.list;
                    console.log(newsList);
                }else{
                    newsList = newsList.concat(res.list);
                    console.log(newsList);
                }
                html = '<div class="head-news">';
                html += '<a href="arctical.html?nav='+nav+'&item='+item+'&id='+newsList[0].id+'">';
                html += '<div class="head-news-img">';
                html += '<img src="'+newsList[0].title_img+'" alt="">';
                html += '</div><div class="head-news-title head-style">';
                html += '<div class="news-send-date">'+newsList[0].date+'</div>';
                html += '<div class="title-text">'+newsList[0].title+'</div></div>';
                html += '<div class="m-news-sub-content">'+newsList[0].sub_content+'</div>';
                html += ' <div class="today-headline">头条详情</div></a></div>';
                for(var i=1;i<newsList.length;i++){
                    html += '<div class="head-news">';
                    html += '<a href="arctical.html?nav='+nav+'&item='+item+'&id='+newsList[i].id+'">';
                    html += '<div class="head-news-title">';
                    html += '<div class="news-send-date">'+newsList[i].date+'</div>';
                    html += '<div class="title-text">'+newsList[i].title+'</div></div>';
                    html += '<div class="m-news-sub-content">'+newsList[i].sub_content+'</div>';
                    html += '</a></div>';
                }
                if(res.ok == 0){

                }else if(res.ok == 1){
                    html += '<div id="getMore">查看更多</div>'
                }
            }

            $('#main-news-box').html(html)
        },{p:page})
    }
    getNewsList(apiUrl,page)
    $('#news-box').on('click','#getMore',function(){
        page++
        getNewsList(apiUrl,page)
    })
})
